//
//  ViewController.m
//  NewsReader
//
//  Created by zhouxiaobo on 15/10/30.
//  Copyright © 2015年 mapath. All rights reserved.
//

#import "Homepage.h"
#import "ColumnInfo.h"
#import "FxGetAdvert.h"
#import "PageInfo.h"
#import "AdvertInfo.h"
#import "NewsPage.h"
#import "VoicePage.h"
#import "ReaderPage.h"
#import "DiscoveryPage.h"
#import "MyPage.h"

@implementation Homepage

- (id) init {
    self = [super init];
    if (self) {
        [self addTabControllers];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *s = [NSString stringWithFormat:@"链接的URL:%@",ColumnURL];
    BASE_INFO_FUN(s);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void) addTabControllers {
    
    //设置tab选中的文字颜色
    self.tabBar.tintColor = [UIColor redColor];
    self.viewControllers = [PageInfo pageControllers];
    
//    NSMutableArray *contrs = [NSMutableArray array];
//
//    FxBasePage *page = nil;
//    UINavigationController *navContr = nil;
//    
//    page = [[NewsPage alloc]init];
//    page.title = @"新闻";
//    page.tabBarItem.image = [UIImage imageNamed:@"NewsIcon.png"];
//    navContr = [[UINavigationController alloc]initWithRootViewController:page];
//    [contrs addObject:navContr];
//    
//    page = [[VoicePage alloc]init];
//    page.title = @"视听";
//    page.tabBarItem.image = [UIImage imageNamed:@"VoiceIcon.png"];
//    navContr = [[UINavigationController alloc]initWithRootViewController:page];
//    [contrs addObject:navContr];
//    
//    page = [[ReaderPage alloc]init];
//    page.title = @"阅读";
//    page.tabBarItem.image = [UIImage imageNamed:@"ReaderIcon.png"];
//    navContr = [[UINavigationController alloc]initWithRootViewController:page];
//    [contrs addObject:navContr];
//    
//    page = [[DiscoveryPage alloc]init];
//    page.title = @"发现";
//    page.tabBarItem.image = [UIImage imageNamed:@"DiscoveryIcon.png"];
//    navContr = [[UINavigationController alloc]initWithRootViewController:page];
//    [contrs addObject:navContr];
//    
//    page = [[MyPage alloc]init];
//    page.title = @"我";
//    page.tabBarItem.image = [UIImage imageNamed:@"MyIcon.png"];
//    navContr = [[UINavigationController alloc]initWithRootViewController:page];
//    [contrs addObject:navContr];
//    
//    self.viewControllers = contrs;
    
}

- (void) testModel {
    NSURL *url = [NSURL URLWithString:ColumnURL];
    NSData *data = [NSData dataWithContentsOfURL:url];
    NSString *json = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    NSDictionary *dict = [FxJsonUtility jsonValueFromString:json];
    NSArray *infos = [ColumnInfo arrayFromDict:dict];
    
    //排序
    infos = [infos sortedArrayUsingSelector:@selector(compare:)];
    
    //比较
    BaseInfo *info1 = [infos objectAtIndex:0];
    BaseInfo *info2 = [infos objectAtIndex:1];
    if ([info1 isEqual:info2]) {
        BASE_INFO_FUN(@"equal");
    }else{
        BASE_INFO_FUN(@"not equal");
    }
}

@end
